const { SyncWaterfallHook } = require("tapable");

class HYCompiler {
  constructor() {
    this.hooks = {
      // waterfall: 当返回值不为undefined时，会将这次返回的结果作为下一次事件的第一个参数
      syncWaterfallHook: new SyncWaterfallHook(["name", "age"]),
    };

    this.hooks.syncWaterfallHook.tap("event1", (name, age) => {
      console.log("event1事件执行了", name, age);
      return "哈哈哈";
    });

    this.hooks.syncWaterfallHook.tap("event2", (name, age) => {
      console.log("event1事件执行了", name, age);
    });
  }
}

setTimeout(() => {
  const compiler = new HYCompiler();
  compiler.hooks.syncWaterfallHook.call("why", 23);
}, 2000);
